package com.nwpu.server.learning.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.nwpu.server.common.response.PageUtils;
import com.nwpu.server.common.response.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.nwpu.server.learning.entity.AlgorithmEntity;
import com.nwpu.server.learning.service.AlgorithmService;



/**
 * 算法名称表
 *
 * @author YuXingZh
 * @email 617058979@qq.com
 * @date 2022-09-18 14:12:11
 */
@RestController
@RequestMapping("learning/algorithm")
public class AlgorithmController {
    @Autowired
    private AlgorithmService algorithmService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = algorithmService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 算法名称
     */
    @RequestMapping("/listName")
    public List<String> listName(@RequestParam(value = "name", required = false) String name){
        // 模糊查询算法名称
        return algorithmService.listName(name);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		AlgorithmEntity algorithm = algorithmService.getById(id);

        return R.ok().put("algorithm", algorithm);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody AlgorithmEntity algorithm){
		algorithmService.save(algorithm);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody AlgorithmEntity algorithm){
		algorithmService.updateById(algorithm);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		algorithmService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
